package com.iflytek.day12._03_override;

class Person4 {
  private String name = "凤姐";
  private int age = 20;

  public Person4() {
    System.out.println("父类无参");
  }

  public Person4(String name, int age) {
    this.name = name;
    this.age = age;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public int getAge() {
    return age;
  }

  public void setAge(int age) {
    this.age = age;
  }
}

class Student4 extends Person4 {
  private double score = 100;

  public Student4() {
    // super(); // 调用父类无参构造方法,默认就存在，可以不写，必须再第一行
    System.out.println("子类无参");
  }

  public Student4(String name, int age, double score) {
    super(name, age);// 调用父类有参构造方法Person(String name , int age)初始化name和age
    this.score = score;
    System.out.println("子类有参");
  }

  public double getScore() {
    return score;
  }

  public void setScore(double score) {
    this.score = score;
  }
}

public class Demo04 {
  public static void main(String[] args) {
    // 调用子类有参数构造方法
    Student4 s4 = new Student4("张三", 20, 99);
    System.out.println(s4.getScore()); // 99
    System.out.println(s4.getName()); // 输出 张三
    System.out.println(s4.getAge()); // 输出 20
  }
}